﻿using System;
using System.ComponentModel;
using Utils.Wpf;
using Visiblox.Charts;

namespace StockAnalyst2.Chart
{
	class ChartViewerVM : ViewModelBase
	{
		#region Attributes

		private bool _isVisible;
		private DateTimeRange _xRange;
		private Zoom _zoom;
		private decimal _chartAreaWidth;

		private readonly ChartData _model;

		#endregion

		#region Properties

		public bool IsVisible
		{
			get
			{
				return _isVisible;
			}
			set
			{
				if (value != _isVisible)
				{
					_isVisible = value;
					base.OnPropertyChanged("IsVisible");
				}
			}
		}

		public DateTimeRange XRange
		{
			get
			{
				return _xRange;
			}
			set
			{
				if (_xRange != value)
				{
					_xRange = value;
					base.OnPropertyChanged("XRange");
				}
			}
		}

		public Zoom Zoom
		{
			get
			{
				return _zoom;
			}
			set
			{
				if (_zoom != value)
				{
					_zoom = value;
					base.OnPropertyChanged("Zoom");
				}
			}
		}

		public decimal ChartAreaWidth
		{
			get
			{
				return _chartAreaWidth;
			}
			set
			{
				if (_chartAreaWidth != value)
				{
					_chartAreaWidth = value;
					base.OnPropertyChanged("ChartAreaWidth");
				}
			}
		}

		public bool IsMainDataLoaded
		{
			get
			{
				return true; // this.DataManager.IsMainDataLoaded;
			}
		}

		public bool IsIndicatorsDataLoaded
		{
			get
			{
				return true; // this.DataManager.IsIndicatorsDataLoaded;
			}
		}

		public bool IsVolumeDataLoaded
		{
			get
			{
				return this.DataManager.IsVolumeDataLoaded;
			}
		}

		public DataManager DataManager { get; private set; }
		public ChartDataVM ChartDataVM { get; private set; }

		#endregion

		#region Public Methods

		public ChartViewerVM(ChartData model)
		{
			_xRange = new DateTimeRange(DateTime.Parse("01/01/2000 07:30:00"), DateTime.Parse("01/01/2000 22:30:00")); // We set the range here to change only the days when loading quotes
			_zoom = new Zoom();

			_model = model;

			this.DataManager = new DataManager(_model);
			this.DataManager.PropertyChanged += DataManager_OnPropertyChanged; // Local object

			this.ChartDataVM = new ChartDataVM(_model);
		}

		#endregion

		#region Event Handlers

		private void DataManager_OnPropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			base.OnPropertyChanged(e.PropertyName);
		}

		#endregion

	}
}
